home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / forms / lineno / editdemo.frm (.txt) next >
Encoding:
Visual Basic Form  |  1992-11-10  |  3.4 KB  |  104 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Form1"
  4.    Height          =   4425
  5.    Left            =   165
  6.    LinkTopic       =   "Form1"
  7.    ScaleHeight     =   4020
  8.    ScaleWidth      =   6630
  9.    Top             =   1140
  10.    Width           =   6750
  11.    Begin Timer Timer1 
  12.       Interval        =   100
  13.       Left            =   3720
  14.       Top             =   120
  15.    End
  16.    Begin TextBox Text2 
  17.       Height          =   285
  18.       Left            =   4440
  19.       TabIndex        =   2
  20.       Text            =   "Click to change focus."
  21.       Top             =   1560
  22.       Width           =   2055
  23.    End
  24.    Begin CommandButton Command1 
  25.       Caption         =   "Exit"
  26.       Height          =   375
  27.       Left            =   4440
  28.       TabIndex        =   1
  29.       Top             =   1080
  30.       Width           =   1095
  31.    End
  32.    Begin TextBox Text1 
  33.       Height          =   3015
  34.       Left            =   480
  35.       MultiLine       =   -1  'True
  36.       TabIndex        =   0
  37.       Text            =   "Text1"
  38.       Top             =   840
  39.       Width           =   3855
  40.    End
  41.    Begin Label Label5 
  42.       Height          =   255
  43.       Left            =   1440
  44.       TabIndex        =   6
  45.       Top             =   480
  46.       Width           =   495
  47.    End
  48.    Begin Label Label4 
  49.       Caption         =   "Line No.:"
  50.       Height          =   255
  51.       Left            =   480
  52.       TabIndex        =   5
  53.       Top             =   480
  54.       Width           =   855
  55.    End
  56.    Begin Label Label3 
  57.       Caption         =   "Character:"
  58.       Height          =   255
  59.       Left            =   480
  60.       TabIndex        =   4
  61.       Top             =   120
  62.       Width           =   855
  63.    End
  64.    Begin Label Label2 
  65.       Height          =   255
  66.       Left            =   1440
  67.       TabIndex        =   3
  68.       Top             =   120
  69.       Width           =   615
  70.    End
  71. 'API function declarations needed to get line number
  72. Declare Function GetFocus Lib "user" () As Integer
  73. Declare Function SendMessage Lib "user" (ByVal a%, ByVal b%, ByVal c%, ByVal d As Any) As Long
  74. Sub Command1_Click ()
  75. End Sub
  76. Sub Form_Load ()
  77. thetext$ = "This is a demonstration of getting the current cursor position and line number from a text box control. "
  78. thetext$ = thetext$ + "Formerly, in VB 1.0, it was almost impossible to always know which line the cursor was on when "
  79. thetext$ = thetext$ + "focus switched from another control to the text box. To see how this works, click on the box to "
  80. thetext$ = thetext$ + "the right, then click again, anywhere inside this text box, or type in the box."
  81. text1.Text = thetext$
  82. End Sub
  83. Function GetLineNo (charpos&)
  84. 'Set constant value
  85. Const EM_linefromchar = &H400 + 25
  86. 'Get current line number from cursor position
  87. pos% = 1 + SendMessage(GetFocus(), EM_linefromchar, -1, 0&)
  88. 'Assign return value to function
  89. GetLineNo = pos%
  90. End Function
  91. Sub Text1_GotFocus ()
  92. timer1.interval = 100 'Sets timer interval to .1 sec.
  93. timer1.Enabled = True 'activates timer routine to get line number when edit control has focus.
  94. End Sub
  95. Sub Text1_LostFocus ()
  96. timer1.Enabled = False 'disables timer when focus is lost.
  97. End Sub
  98. Sub Timer1_Timer ()
  99. label2.Caption = text1.SelStart 'gets character position
  100. pos& = text1.SelStart    'assign to variable
  101. currline = GetLineNo(pos&) 'calls linenumber function
  102. label5.Caption = currline 'displays current line number
  103. End Sub
  104.